/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entidades.Post;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author PARTICULAR
 */
public class PostDao implements Dao<Post> {

    private EntityManager em = EMF.get().createEntityManager();

    @Override
    public Post inserir(Post obj) {
        synchronized (this) {
            em.getTransaction().begin();
            em.merge(obj);
            em.getTransaction().commit();
        }
        return obj;
    }

    @Override
    public Post pesquisar(Long obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void excluir(Post obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Post> getAll() {
       try {
            Query q = em.createQuery("select post from Post as post");
            return q.getResultList();
        } catch (Exception e) {
            System.out.println("Excecao HQL.." + e);
            return null;
        }
    }
}
